﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Member.DAL;
using System.Linq.Expressions;
using Member.IDAL;

namespace Member.BLL
{
    public partial class BaseBLL<T> where T : class,new()
    {
        public BaseBLL()
        {
            setDAl();
        }
        //实例化
        public IBaseDAL<T> Dal;

        public virtual  void setDAl(){}
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t"></param>
        /// <returns>是否添加成功</returns>
        public bool Add(T t)
        {
            Dal.Add(t);
            return Dal.SaveChange();
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="t"></param>
        /// <returns>是否更新成功</returns>
        public bool Update(T t)
        {
            Dal.Update(t);
            return Dal.SaveChange();
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="t"></param>
        /// <returns>是否删除成功</returns>
        public bool Delete(T t)
        {
            Dal.Delete(t);
            return Dal.SaveChange();
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="WhereLambda">条件表达式</param>
        /// <returns></returns>
        public IQueryable<T> GetModels(Expression<Func<T, bool>> WhereLambda)
        {
            return Dal.GetModels(WhereLambda);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="Type"></typeparam>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="isAsc">是否排序</param>
        /// <param name="OrderByLambda">排序字段</param>
        /// <param name="WhereLambda">条件</param>
        /// <returns></returns>
        public IQueryable<T> GetModelsByPage<Type>(int pageSize,int pageIndex,bool isAsc,
            Expression<Func<T, Type>> OrderByLambda, Expression<Func<T, bool>> WhereLambda)
        {
            return Dal.GetModelsByPage(pageSize, pageIndex, isAsc, OrderByLambda, WhereLambda);
        
        }
    }
}
